/**
 * 
 */
package lbs.locationretreival;

/**
 * @author cris
 *
 */


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;	// provides location services
import android.location.LocationListener;	// // listens for change in location

import java.util.List;


/* show liste of different location providers and their location esitmate*/
public class ProviderList extends Activity implements LocationListener {
	
	private LocationManager l_manager;
	private TextView view;
	private Location location;
	private String l_provider;	// location provider
	private Criteria criteria;
//	private final LocationListener listener;
	
	private static final long MIN_TIME_FOR_UPDATE =  2000;	//milliseconds
	private static final int MIN_DISTANCE_FOR_UPDATE =  2;	//meters
	
	/* define accurancy and power requirements for location gathering */
	private static final int ACCURACY = Criteria.ACCURACY_FINE;
	private static final int POWER = Criteria.POWER_LOW;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        view = (TextView) findViewById(R.id.view1);
        
        l_manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
             
        
        criteria = new Criteria();
        criteria.setAccuracy(ACCURACY);
        criteria.setPowerRequirement(POWER);
   
        //location provider could be gps or network based on criteria
        l_provider = l_manager.getBestProvider(criteria, true);
        
        
        List<String> providers = l_manager.getProviders(true);
        view.setText("Location Providers....\n");
        
        for (String p : providers){
        	
        	  l_manager.requestLocationUpdates(l_provider, MIN_TIME_FOR_UPDATE, 
  	        		MIN_DISTANCE_FOR_UPDATE, this);
        	  
        	  if(p != null){
        		  location = l_manager.getLastKnownLocation(p);
        		  view.append("\n\t" + p + "\nlat: " + location.getLatitude()
		       		+ " \nlong: " + location.getLongitude());
        	  }
        }
        }


	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}
      
    
    
}
